using System.Web;
using BoxBinary.AspectCache.Core.ErrorLogging;

namespace BoxBinary.AspectCache.Core.Logging
{
    public class ErrorLogProvider
    {
        #region Singleton Access

        private static readonly ErrorLogProvider _current = new ErrorLogProvider();

        /// <summary>
        /// Gets the current ErrorLogProvider.
        /// </summary>
        /// <value>The current ErrorLogProvider.</value>
        public static ErrorLogProvider Current
        {
            get
            {
                if (HttpContext.Current == null)
                    return _current;
                else
                {
                    string _CurrentKey = "kjl234hkl2jh3";
                    ErrorLogProvider oCheck = null;
                    if (HttpContext.Current != null)
                    {
                        oCheck = (ErrorLogProvider) HttpContext.Current.Items[_CurrentKey];

                        if (oCheck == null)
                        {
                            oCheck = new ErrorLogProvider();
                            HttpContext.Current.Items[_CurrentKey] = oCheck;
                        }
                    }

                    return oCheck;
                }
            }
        }

        #endregion Singleton Access

        private ILogProvider _iLog;

        public ILogProvider DefaultErrorLogger
        {
            get
            {
                if (_iLog == null)
                {
                    _iLog = ErrorLogging.ConfigSection.GetSelectedLogProvider();
                }
                return _iLog;
            }
        }
    }
}